package com.egghiro.framework.j2se.game.core;

public final class Version {

    private final int major;

    private final int minor;

    private final int build;

    /**
     * 版本信息
     * 
     * @param major
     * @param minor
     * @param build
     */
    Version(final int major, final int minor, final int build) {
        this.major = major;
        this.minor = minor;
        this.build = build;
    }

    @Override
    public boolean equals(final Object obj) {
        if (obj instanceof Version) {
            final Version other = (Version) obj;
            return (this.major == other.getMajor())
                    && (this.minor == other.getMinor())
                    && (this.build == other.getBuild());
        }
        return false;
    }

    public int getBuild() {
        return this.build;
    }

    public int getMajor() {
        return this.major;
    }

    public int getMinor() {
        return this.minor;
    }

    @Override
    public String toString() {
        return this.major + "." + this.minor + "." + this.build;
    }

    public boolean isNewerThan(final Version v) {
        if (this.major > v.getMajor()) {
            return true;
        } else if (this.major < v.getMajor()) {
            return false;
        }
        if (this.minor > v.getMinor()) {
            return true;
        } else if (this.minor < v.getMinor()) {
            return false;
        }
        if (this.build > v.getBuild()) {
            return true;
        }
        return false;
    }

}
